package com.study.controller;

import com.study.service.ShortLinkService;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author canace
 * @version 1.0
 * @description 短链接跳转控制类
 * @date 2024/2/6 13:15
 */

@RestController
@RequiredArgsConstructor
public class ShortLinkGoToController {

    private final ShortLinkService shortLinkService;

    /**
     * 短链接跳转原链接
     *
     * @param shortUri 短链接后缀
     * @param request  请求
     * @param response 响应
     */
    @GetMapping("/{short-uri}")
    public void restoreUrl(@PathVariable("short-uri") String shortUri, ServletRequest request, ServletResponse response) {
        shortLinkService.restoreUrl(shortUri, request, response);
    }

    /**
     * 短链接不存在页面
     *
     * @return 页面不存在
     */
    @GetMapping("/page/notfound")
    public String notFoundPage() {
        return "页面不存在";
    }
}
